package com.cwj.jmh;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author chenwujie
 * @date 2021-03-08 09:00
 */
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@State(Scope.Thread)
@Fork(1)

@Warmup(iterations = 3)
@Measurement(iterations = 5)
public class JmhTest {
    public static void main(String[] args) throws RunnerException {
        Options opts = new OptionsBuilder().include(JmhTest.class.getSimpleName()).build();
        new Runner(opts).run();

    }

    @Benchmark
    public void test(){
        List<Object> objects = new ArrayList<>();
        for (int i = 0; i < 10000; i++) {
            objects.add(i);
        }
    }

    @Benchmark
    public void test2(){
        List<Object> objects = new LinkedList<>();
        for (int i = 0; i < 10000; i++) {
            objects.add(i);
        }
    }
}
